<?php
error_reporting(E_ALL ^ E_NOTICE);

set_time_limit(0);
date_default_timezone_set("PRC"); //timezone

$db1=mysql_connect("localhost","root","root"); 
mysql_select_db('faithwar',$db1); 

#$dateTime = date("Y-m-d",strtotime("-2 day"));
$dateTime = date("Y-m-d");
//$dateTime = '2012-08-09';

   $deviceid_query = mysql_query("select deviceid deviceid from faithwar_level"); //id


while($deviceid = mysql_fetch_array($deviceid_query))
{

    $level_query = mysql_query("SELECT level from faithwar_all where deviceid= '$deviceid[deviceid]' ORDER BY `date` DESC limit 1");
    $level = mysql_fetch_array($level_query);
   //var_dump($money[0]);

     $sql = "UPDATE  faithwar_level SET level= '$level[level]' WHERE deviceid= '$deviceid[deviceid]'";
     
   if(mysql_query($sql,$db1)){
    echo "1 update is ok!";
} else {
    echo "failed".mysql_error();
}

}
mysql_close($db1);
?>